<template>
  <view class="imagemodal">
    <view class="cu-modal" :class="showModal ? 'show' : ''">
      <view class="cu-dialog">
        <view class="cu-bar bg-white justify-end top">
          <view class="content">检测到{{itemDetail.tbk_pwd ? '可' : '不可'}}转换的商品</view>
          <view class="action" @click="close">
            <text class="iconfont icon-guanbi"></text>
          </view>
        </view>
        <view class="bg-img middle">
          <ImageLoad v-if="itemDetail.pict_url" :src="itemDetail.pict_url" mode="widthFix"/>
          <view class="item_title" v-if="itemDetail.title">{{itemDetail.title}}</view>
          <view class="item_tip" v-if="!itemDetail.title">您复制的商品已下架或无任何优惠信息，不过您仍然可以点击“商品详情”，查看历史价格趋势</view>
        </view>
        <view class="cu-bar bg-white bottom">
          <view class="action margin-0 flex-sub" v-if="itemDetail.tbk_pwd" @click="copyTkl">复制口令</view>
          <view class="action margin-0 flex-sub" v-if="!itemDetail.tbk_pwd" @click="goSearch">找相似</view>
          <view class="action margin-0 flex-sub solid-left go_detail" @click="goDetail">商品详情</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import ImageLoad from '@/pages/pagecomponents/other/imageload'
  export default {
    components: {
      ImageLoad,
    },
    data() {
      return {
        itemDetail: {
          // title: '珊瑚绒四件套冬季加厚保暖法莱绒床单被套三件套法兰绒床上用品',
          // pict_url: "https://img.alicdn.com/bao/uploaded/i4/1586515126/O1CN019RSq6Y1njknpKNIc0_!!0-item_pic.jpg",
          // num_iid: '604222181852',
          // tbk_pwd: '￥154156415641563￥'
        },
        showModal: false,
        clipboardData: '', // 剪贴板淘口令
      }
    },
    computed:{
    },
    created() {
    },
    methods: {
      checkClipboard(){ //检测剪贴板
        // #ifndef H5
        uni.getClipboardData({
          success: res => {
            this.clipboardData = res.data
            let clipboardData = res.data; // 当前剪贴板内容
            if (clipboardData && /[￥€$₤₳¢¤฿฿₵₡₫ƒ₲₭£₥₦₱〒₮₩₴₪៛﷼|₢ℳ₰₯₠₣₧ƒ][a-zA-Z0-9]{8,12}[￥€$₤₳¢¤฿฿₵₡₫ƒ₲₭£₥₦₱〒₮₩₴₪៛﷼|₢ℳ₰₯₠₣₧ƒ]/.test(clipboardData)) {
              // 清空剪贴板
              uni.setClipboardData({
                data: '.',
                success: function() {
                  uni.hideToast(); // 隐藏默认提示框
                }
              });
              // 获取商品信息
              this.$api.wyapi.getTkl({
                para: clipboardData,
                deepcoupon: 1, // 默认值0，1表示对联盟产品无官方优惠券时，则进行检查是否有商家合作券
                detail: 1, // 获取详细商品信息
              }).then(res => {
                this.showModal = true
                this.itemDetail = res.data ? res.data : res
              })
            }
          }
        });
        // #endif
      },
      copyTkl(){
        let copyText = ''
        // #ifndef H5
        copyText = `淘口令:【${this.itemDetail.tbk_pwd}】\r\n下单方法：复制此条信息→打开手淘领券`
        uni.setClipboardData({
          data: copyText,
          success: function() {
            uni.hideToast(); // 隐藏默认提示框
            uni.showToast({
              title: '复制成功'
            });
          }
        });
        // #endif
      },
      goSearch(){
        uni.navigateTo({
          url: `/pages/search/searchresult?keyWords=${this.itemDetail.num_iid}`
        });
      },
      goDetail(){
        this.showModal = false
        if(this.itemDetail.pict_url){ // 有优惠信息
          uni.navigateTo({
            url: `/pages/itemdetail/index?goodsId=${this.itemDetail.num_iid}`
          });
        } else { // 无优惠信息，只进入查看价格趋势
          this.$api.user.tklToUrl({
            tkl: this.clipboardData,
          }).then(res => {
            uni.navigateTo({
              url: `/pages/itemdetail/index?itemLink=${encodeURIComponent(res.data)}&&id=${-1}&&goodsId=${-1}`
            });
          })
        }
        
      },
      close(){
        this.showModal = false
      },
    }
  }
</script>

<style scoped lang="scss">
  .imagemodal{
    .top{
      .content{
        color: #294d7d;
      }
      .icon-guanbi{
        font-size: 50upx;
      }
    }
    .middle{
      .item_title{
        text-align: center;
        font-size: 32upx;
        padding: 0 30upx;
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
      }
      .item_tip{
        text-align: left;
        padding: 0 30upx;
      }
    }
    .bottom{
      .action{
        height: 100upx;
      }
      .go_detail{
        color: #294d7d;
        font-weight: 600;
      }
    }
  }
</style>
